<?php
    if(!defined('LT2N_ADMIN')){die('bạn không có quyền truy cập'); }
    $db = new Model();
    $module['name'] = $_GET["mod"];
    if ( $module['name'] == 'software' ) {
        if ( isset( $_GET['act'] ) ) {
            $act = $_GET['act'];

            if ( $act == 'list' ) {
                $software = $db->select( LT2N_PREFIX . '_software', "", "ORDER BY `software_name` ASC" );
            } elseif ( $act == 'add' ) {
                initalize_post_var( 'software_name', 'software_desc');
                if(isset($_SESSION['permission']) && $_SESSION['permission'] != PERMISSION_USER && $_SESSION['permission'] != PERMISSION_MANAGER ){
                    if(isset($_POST['btnAdd'])){
                        $software_name   = $_POST['software_name'];

                        $db->select( LT2N_PREFIX.'_software', array( '`software_name`' => $software_name ) );
                        if ( $db->check( array( true => false ) ) ) {
                            $errors[] = '<div class="error" >Phần mềm '. $software_name .' đã tồn tại.</div>';
                        } else {

                            $software_desc   = $_POST['software_desc'];
                            $list = array(
                                'software_name' =>$software_name,
                                'software_desc' =>$software_desc
                            );


                            $db->insert(LT2N_PREFIX.'_software',$list);
                            if($db->checkQuery() == 1){
                                $success[] = '<div class="success" >Đã thêm thành công.</div>';
                                header("Location: index.php?mod=software&act=list&success=".SUCCESS_ADD);
                            } else {
                                $errors[] = '<div class="error" >Thêm phần mềm mới mới thất bại.</div>';
                            }
                        }

                    }
                }
            }elseif ( $act == 'edit' ) {

            } elseif ( $act == 'search' ) {
                $software = array();
                $s = '';
                if ( isset( $_POST['btnSearchSoftware'] ) ) {
                    $s = ( isset( $_POST['s'] ) ) ? $_POST['s'] : '';
                    $software = $db->select( LT2N_PREFIX.'_software', "`software_name` LIKE '%". $s ."%'" );
                }
            } elseif ( $act == '' ) {
                header("Location: index.php?mod=software&act=list");
            }
            require(LT2N_VIEW_PATH.$module["name"]."/".$act.".php");
        }
    }

?>